import { SActiveToClient } from "../../../../Message/Public/SActiveToClient";
import { SecTimer } from "../../../../com/gengine/core/frame/SecTimer";
import { TimerType } from "../../../../com/gengine/core/frame/TimerType";
import { ClockManager } from "../../manager/ClockManager";
import { Cache } from "../../cache/Cache";
import { OpenRechargeGiftBagConfig } from "../../resource/OpenRechargeGiftBagConfig";
import { ConsumeDayData } from "./ConsumeDayData";
import { ConsumeCountData } from "./ConsumeCountData";
type int = number;
//class ConsumeDataUtil
    
    export  class ConsumeDataUtil
    {
        constructor()
        {
            
            this._hadGetCodes = [];
            this._hadGetDayCodes = [];
            return;
        }

        public get hadGetCodes(): Array<any>
        {
            return this._hadGetCodes;
        }

        public set hadGetCodes(arg1: Array<any>)
        {
            this._hadGetCodes = arg1;
            return;
        }

        public get hadGetDayCodes(): Array<any>
        {
            return this._hadGetDayCodes;
        }

        public set hadGetDayCodes(arg1: Array<any>)
        {
            this._hadGetDayCodes = arg1;
            return;
        }

        public set activeToClient(arg1: SActiveToClient)
        {
            var loc1=null;
            var loc2=null;
            this._activeToClient = arg1;
            if (!this._secTimer) 
            {
                this._secTimer = new SecTimer();
                this._secTimer.addListener(TimerType.ENTERFRAME, this.onTimerEnterFrameHandler);
                this._secTimer.addListener(TimerType.COMPLETE, this.onTimerCompleteHandler);
            }
            if (this._activeToClient) 
            {
                loc1 = ClockManager.instance.nowDate;
                loc2 = this._activeToClient.endDt;
                this._resTime = (loc2.time - loc1.time) / 1000;
            }
            this._secTimer.reset();
            this._secTimer.repeatCount = this._resTime;
            this._secTimer.start();
            return;
        }

        public get activeToClient(): SActiveToClient
        {
            return this._activeToClient;
        }

        public get consumeType(): int
        {
            if (this._activeToClient) 
            {
                return this._activeToClient.code;
            }
            return 0;
        }

        /* internal  */onTimerEnterFrameHandler(arg1: SecTimer): void
        {
            --this._resTime;
            return;
        }

        /* internal  */onTimerCompleteHandler(arg1: SecTimer): void
        {
            arg1.stop();
            arg1.isDelete = false;
            return;
        }

        public get isRechargeActive(): Boolean
        {
            var loc1=ClockManager.instance.nowDate;
            var loc2=this._activeToClient.startDt;
            var loc3=this._activeToClient.endDt;
            var loc4=false;
            if (this._activeToClient && this._resTime > 0 && loc1.time >= loc2.time && loc1.time <= loc3.time) 
            {
                loc4 = true;
            }
            return loc4;
        }

        public get restTime(): int
        {
            return this._resTime;
        }

        public isHadGet(arg1: int): Boolean
        {
            var loc1=false;
            var loc2=0;
            while (loc2 < this.hadGetCodes.length) 
            {
                if (arg1 == this.hadGetCodes[loc2]) 
                {
                    loc1 = true;
                    break;
                }
                ++loc2;
            }
            return loc1;
        }

        public isHadGetDay(arg1: int): Boolean
        {
            var loc1=false;
            var loc2=0;
            while (loc2 < this.hadGetDayCodes.length) 
            {
                if (arg1 == this.hadGetDayCodes[loc2]) 
                {
                    loc1 = true;
                    break;
                }
                ++loc2;
            }
            return loc1;
        }

        public isHadGetAllGift(arg1: int, arg2: Boolean=false): Boolean
        {
            var loc4=null;
            var loc5=0;
            var loc6=null;
            var loc7=0;
            var loc8=0;
            var loc1=Cache.instance.active.isActiveInEffect(arg1);
            var loc2=false;
            var loc3=[];
            if (arg2) 
            {
                loc3 = this.hadGetDayCodes;
            }
            else 
            {
                loc3 = this.hadGetCodes;
            }
            if (loc1) 
            {
                loc4 = OpenRechargeGiftBagConfig.instance.getConsumeCountGiftBag(arg1, Cache.instance.role.consumeWorldLevle);
                loc5 = 0;
                loc7 = 0;
                while (loc7 < loc4.length) 
                {
                    loc6 = loc4[loc7];
                    loc8 = 0;
                    while (loc8 < loc3.length) 
                    {
                        if (loc6.code == loc3[loc8]) 
                        {
                            loc5 = loc5 + 1;
                            break;
                        }
                        ++loc8;
                    }
                    ++loc7;
                }
                if (!(loc3.length == 0) && loc5 >= loc4.length) 
                {
                    loc2 = true;
                }
            }
            else 
            {
                loc2 = true;
            }
            return loc2;
        }

        public isCanGetGift(arg1: Boolean=false): Boolean
        {
            var loc1=0;
            var loc3=null;
            if (arg1) 
            {
                loc1 = ConsumeDayData.consumeType;
            }
            else 
            {
                loc1 = ConsumeCountData.consumeType;
            }
            var loc2=OpenRechargeGiftBagConfig.instance.getConsumeCountGiftBag(loc1, Cache.instance.role.consumeWorldLevle);
            var loc4=0;
            var loc5=loc2;
            for(loc3 of loc5) 
            {
                if ((loc3.activetype == 1 || loc3.activetype == 2 || loc3.activetype == 4) && !arg1) 
                {
                    if (Cache.instance.role.consumeCount >= loc3.target && !this.isHadGet(loc3.code)) 
                    {
                        return true;
                    }
                    continue;
                }
                if (!(loc3.activetype == 5 || loc3.activetype == 6)) 
                {
                    continue;
                }
                if (!(Cache.instance.role.consumeDay >= loc3.target && !this.isHadGetDay(loc3.code))) 
                {
                    continue;
                }
                return true;
            }
            return false;
        }

        /* internal */ /* var */_activeToClient: SActiveToClient;

        /* internal */ /* var */_secTimer: SecTimer;

        /* internal */ /* var */_resTime: int;

        /* internal */ /* var */_hadGetCodes: Array<any>;

        /* internal */ /* var */_hadGetDayCodes: Array<any>;
    }
